<?php
/**
 * Created by PhpStorm.
 * User: fang_
 * Date: 2018/8/9
 * Time: 9:15
 */

require_once 'server.php';


function get_all_bus_info()
{
    $buses_line = file_get_contents('bus.txt');
    $buses_line = explode("\n",$buses_line);
    $fail = array();
    foreach ($buses_line as $line)
    {
        try {
            $json_result = get_bus_direction($line);
            $result = json_decode($json_result);
            $bus_direction = (string)key($result);
            $result = json_decode(get_bus_stop($line, $bus_direction));
            $stop = key($result);
            $result = json_decode(get_bus_details($line, $bus_direction, $stop), $assoc = true);
            print("\n");
            #var_dump($result);
            $info[$line] = array("bus_info" => $result["bus_info"], "has_bus" => $result["bus_coming"]);
            #var_dump($info);
        } catch (Exception $e)
        {
            $fail[] = $line;
        }
    }
    $ser = serialize($info);
    file_put_contents('bus_info.txt',$ser);
}

function get_all_bus_direction()
{
    $buses_line = file_get_contents('bus.txt');
    $buses_line = explode("\n",$buses_line);
    $fail = array();
    $direction = array();
    f
    foreach ($buses_line as $line)
    {
        try {
            $json_result = get_bus_direction($line);
            $result = json_decode($json_result,false);
            foreach ($result -> $key as $value){
            }
            #var_dump($info);
        } catch (Exception $e)
        {
            $fail[] = $line;
        }
    }
    $ser = serialize($info);
    file_put_contents('bus_info.txt',$ser);
}

get_all_bus_info();

